<template>
  <div class="health-box">
    <div class="title-box">
      <div class="title-item-left">
        <span class="text-icon" />
        健康监测
      </div>
    </div>
    <div class="healthMonitoring">
      <div class="healthMonitoringLeft">
        <div class="left-health">
          <div
            :class="signSelIndex === index ? 'sign-item sign-item-active' : 'sign-item'"
            v-for="(item, index) in signData"
            :key="index"
            @click="signHandle(index, item)"
          >
            <span class="sign-item-name">{{ item.name }}</span>
          </div>
        </div>
      </div>
      <div class="healthMonitoringRight">
        <div class="right-health">
          <div class="title-item" style="margin-bottom: 8px">
            <span>
              {{ chartTitle }}
              <a-tooltip>
                <template #title>
                  <pre>{{ chartTip }}</pre>
                </template>
                <QuestionCircleOutlined
                  v-if="signSelIndex !== 0 && signSelIndex !== 1"
                  style="cursor: pointer"
                />
              </a-tooltip>
            </span>
            <!-- <div style="padding-right: 5px">
            <template v-if="signSelIndex == 6">
              <a-radio-group
                v-model:value="bsType"
                name="radioGroup"
                size="small"
                @change="bsTypeChange"
                button-style="solid"
              >
                <a-radio-button value="fbg">空腹血糖</a-radio-button>
                <a-radio-button value="pbg">餐后2小时</a-radio-button>
              </a-radio-group>
            </template>
          </div> -->
          </div>

          <div class="chart-box" style="position: relative">
            <div style="position: absolute; right: 5px; z-index: 100; width: 100%">
              <div
                v-if="signSelIndex == 6"
                style="float: left; margin-left: 6px; line-height: 32px"
              >
                <a-radio-group
                  v-model:value="bsType"
                  name="radioGroup"
                  size="small"
                  @change="bsTypeChange"
                  button-style="solid"
                >
                  <a-radio-button value="fbg">空腹血糖</a-radio-button>
                  <a-radio-button value="pbg">餐后2小时</a-radio-button>
                </a-radio-group>
              </div>
              <div class="dateLeft" style="">
                <RightOutlined @click="targetTime('before')" />
                <p class="name">{{ getShowDateStart }} ~ {{ getShowDateEnd }}</p>
                <RightOutlined @click="targetTime('after')" />
              </div>
              <div style="float: right">
                <a-radio-group
                  @change="radioChange"
                  v-model:value="getDateValue"
                  style="margin-bottom: 16px"
                >
                  <a-radio-button value="week">周</a-radio-button>
                  <a-radio-button value="month">月</a-radio-button>
                  <a-radio-button value="year">年</a-radio-button>
                </a-radio-group>
                <!-- <a-range-picker
                  @change="chatTimeChange"
                  allowClear
                  style="width: 300px"
                  v-model:value="chatTime"
                  showTime
                  format="YYYY-MM-DD HH:mm"
                /> -->
              </div>
              <div style="clear: both" />
            </div>
            <div
              v-if="
                (sericeData.length &&
                  sericeData[0] &&
                  sericeData[0].data &&
                  sericeData[0].data.length > 0) ||
                (sericeDataSleepList && sericeDataSleepList.length > 0 && sleepValue == 'sleep')
              "
              id="chart-main"
            />
            <a-empty
              :image="simpleImage"
              v-else
              style="height: 240px; padding-top: 100px; margin-top: 0"
            />
            <div class="title-item">记录</div>
            <div id="chart-tab">
              <a-table
                class="table"
                size="small"
                :loading="loading"
                :dataSource="List"
                :columns="columns"
                :pagination="pagination"
              >
                <template #bodyCell="{ column, record, index }">
                  <template
                    v-if="
                      column.dataIndex == 'no' &&
                      (sleepValue == 'blood_fat' || sleepValue == 'liver_function')
                    "
                  >
                    {{ record.noNumber }}
                  </template>
                  <template
                    v-if="
                      column.dataIndex == 'no' &&
                      sleepValue != 'blood_fat' &&
                      sleepValue != 'liver_function'
                    "
                  >
                    {{ (pagination.current - 1) * pagination.pageSize + index + 1 }}
                  </template>
                  <!-- 睡眠 -->
                  <template v-if="column.dataIndex == 'bs'">
                    <span v-if="record.fbg">{{ record.fbg }}</span>
                    <span v-else>{{ record.pbg }}</span>
                  </template>

                  <template v-if="column.dataIndex == 'nameTitle'">
                    <span>{{ record.names }}</span>
                  </template>
                  <template
                    v-if="
                      column.dataIndex == 'dataSource' &&
                      (sleepValue == 'spo2' ||
                        sleepValue == 'height' ||
                        sleepValue == 'weight' ||
                        sleepValue == 'bmi' ||
                        sleepValue == 'whr' ||
                        sleepValue == 'bp' ||
                        sleepValue == 'heart_rate')
                    "
                  >
                    <span>{{ record.dataSource }}</span>
                  </template>
                  <template
                    v-if="
                      column.dataIndex == 'dataSource' &&
                      (sleepValue == 'blood_ketone' ||
                        sleepValue == 'uric_acid' ||
                        sleepValue == 'blood_fat' ||
                        sleepValue == 'liver_function' ||
                        sleepValue == 'water' ||
                        sleepValue == 'sleep' ||
                        sleepValue == 'blood_sugar')
                    "
                  >
                    <span>{{ record.dataSourceTwo }}</span>
                  </template>
                  <template v-if="column.dataIndex == 'bmi'">
                    <span>{{ record.bmi ? record.bmi.toFixed(1) : '' }}</span>
                  </template>
                  <template v-if="column.dataIndex == 'paramValue' && sleepValue == 'sleep'">
                    <span>{{
                      record.paramValue &&
                      JSON.parse(record.paramValue) &&
                      JSON.parse(record.paramValue).sleepDuration
                        ? JSON.parse(record.paramValue).sleepDuration
                        : ''
                    }}</span>
                  </template>
                  <template v-if="column.dataIndex == 'timeFat'">
                    <span>{{
                      record.timeFat ? formatDateTime(record.timeFat, 'date-h-m') : ''
                    }}</span>
                  </template>
                  <template v-if="column.dataIndex == 'collectTime'">
                    <span>{{
                      record.collectTime ? formatDateTime(record.collectTime, 'date-h-m') : ''
                    }}</span>
                  </template>
                  <template v-if="column.dataIndex == 'bs'">
                    <span v-if="record.fbg">{{ record.fbg }}</span>
                    <span v-else>{{ record.pbg }}</span>
                  </template>
                  <template v-if="column.dataIndex == 'normalFlagName'">
                    <span
                      :style="{ color: record.normalFlagName == '正常' ? '#00B42A' : '#F53F3F' }"
                    >
                      {{ record.normalFlagName }}
                    </span>
                    <!-- <span v-else-if="record.normalFlag == 'L' && signSelCode[0] =='bmi'">偏低</span> -->
                  </template>
                </template>
              </a-table>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import type { Dayjs } from 'dayjs'
import dayjs from 'dayjs'
import { QuestionCircleOutlined, RightOutlined } from '@ant-design/icons-vue'
type RangeValue = [Dayjs, Dayjs]
import {
  getPatientTest,
  getPatientSigns,
  getNewPatientSigns,
  reportChart,
  queryUserHisReportDetail,
  infoCharts
} from '@/api/patientMana/index'
import * as echarts from 'echarts'
import { Empty } from 'ant-design-vue'
const simpleImage = Empty.PRESENTED_IMAGE_SIMPLE

import heightPic from '@/assets/patient/height.png'
import weightPic from '@/assets/patient/weight.png'
import bmiPic from '@/assets/patient/bmi.png'
import whrPic from '@/assets/patient/whr.png'
import bpPic from '@/assets/patient/bp.png'
import heartRatePic from '@/assets/patient/heartRate.png'
import bgPic from '@/assets/patient/bg.png'
import spo2Pic from '@/assets/patient/spo2.png'

const loading = ref(false)
const List = ref([])
// getDateValue  类型
const getDateValue = ref('week')
//显示的值
const getShowDateStartOld = ref('')
const getShowDateEndOld = ref('')
const getShowDateStart = ref('')
const getShowDateEnd = ref('')

const bloodSugarList = ref([])
const sericeDataSleepList = ref([])
const sericeDataLists = ref([])

const pagination = ref({
  current: 1,
  pageSize: 10,
  onChange: (current, size) => {
    pagination.value.current = current
    pagination.value.pageSize = size
  },
  showQuickJumper: true
})
const initcolumns = ref([
  {
    title: '编号',
    dataIndex: 'no',
    key: 'no'
  },
  {
    title: '数据来源',
    dataIndex: 'dataSource',
    key: 'dataSource'
  },
  {
    title: '测量时间',
    dataIndex: 'collectTime',
    key: 'collectTime'
  }
])

const columns: any = ref([])
const sleepValue = ref('')
let myChart: any = undefined
const bsType = ref('')
const signData = ref([
  {
    name: '身高',
    value: '-',
    unit: 'cm',
    time: '',
    hospital: '',
    status: '',
    code: 'height',
    decimal: 1,
    icon: heightPic
  },
  {
    name: '体重',
    value: '-',
    unit: 'kg',
    time: '',
    hospital: '',
    status: '',
    code: 'weight',
    decimal: 2,
    icon: weightPic
  },
  {
    name: 'BMI',
    value: '-',
    unit: '',
    time: '',
    hospital: '',
    status: '',
    code: 'bmi',
    decimal: 2,
    icon: bmiPic
  },
  {
    name: '腰臀比',
    value: '-',
    unit: '',
    time: '',
    hospital: '',
    status: '',
    code: 'whr',
    decimal: 2,
    icon: whrPic
  },
  {
    name: '血压',
    value: '-',
    value1: '-',
    unit: 'mmHg',
    time: '',
    hospital: '',
    status: '',
    status1: '',
    code: 'bp',
    decimal: 0,
    icon: bpPic
  },
  {
    name: '心率',
    value: '-',
    unit: '次/分',
    time: '',
    hospital: '',
    status: '',
    code: 'heartRate',
    decimal: 0,
    icon: heartRatePic
  },
  {
    name: '血糖',
    value: '-',
    unit: 'mmol/L',
    time: '',
    hospital: '',
    status: '',
    code: 'blood_sugar',
    decimal: 1,
    icon: bgPic
  },
  {
    name: '血氧',
    value: '-',
    unit: '%',
    time: '',
    hospital: '',
    status: '',
    code: 'spo2',
    decimal: 0,
    icon: spo2Pic
  },
  {
    name: '血酮',
    value: '-',
    unit: '',
    time: '',
    hospital: '',
    status: '',
    code: 'blood_ketone',
    decimal: 0,
    icon: spo2Pic
  },
  {
    name: '尿酸',
    value: '-',
    unit: '',
    time: '',
    hospital: '',
    status: '',
    code: 'uric_acid',
    decimal: 0,
    icon: spo2Pic
  },
  {
    name: '睡眠',
    value: '-',
    unit: '',
    time: '',
    hospital: '',
    status: '',
    code: 'sleep',
    decimal: 0,
    icon: spo2Pic
  },
  {
    name: '饮水',
    value: '-',
    unit: '',
    time: '',
    hospital: '',
    status: '',
    code: 'water',
    decimal: 0,
    icon: spo2Pic
  },
  {
    name: '血脂',
    value: '-',
    unit: '',
    time: '',
    hospital: '',
    status: '',
    code: 'blood_fat',
    decimal: 0,
    icon: spo2Pic
  },
  {
    name: '肝功能',
    value: '-',
    unit: '',
    time: '',
    hospital: '',
    status: '',
    code: 'liver_function',
    decimal: 0,
    icon: spo2Pic
  }
])

const signLabel = reactive([
  {
    name: '血压',
    code: 'sbp'
  },
  {
    name: '腰臀比',
    code: 'whr'
  },
  {
    name: '肝功能',
    code: 'liver_function'
  },
  {
    name: '血脂',
    code: 'blood_fat'
  },
  {
    name: '体重',
    code: 'weight'
  },
  {
    name: '血糖',
    code: 'blood_sugar'
  },
  {
    name: '饮水',
    code: 'water'
  },
  {
    name: '睡眠',
    code: 'sleep'
  },
  {
    name: '血压',
    code: 'dbp'
  },
  {
    name: '血酮',
    code: 'blood_ketone'
  },
  {
    name: '心率',
    code: 'heartRate'
  },
  {
    name: '血氧',
    code: 'spo2'
  },
  {
    name: '尿酸',
    code: 'uric_acid'
  },
  {
    name: 'BMI',
    code: 'bmi'
  },
  {
    name: '身高',
    code: 'height'
  },
  {
    name: '体重',
    code: 'weight'
  }
])

const signSelIndex = ref(0)
const signSelCode = ref([])
const chatTime = ref([])
const patientEmpi = ref()
const chartTitle = ref('')
const chartTip = ref('')
const yAxisName = ref('')

const patientData = ref()
// charts
const xAxisData: any = ref([])
const sericeData: any = ref([])
const init = async (id, data, labelName?: any) => {
  getShowDateStartOld.value = getCurrentWeekDates().start
  getShowDateEndOld.value = getCurrentWeekDates().end
  getShowDateStart.value = formatDateTime(getCurrentWeekDates().start, 'check-Y-D')
  getShowDateEnd.value = formatDateTime(getCurrentWeekDates().end, 'check-Y-D')
  getDateValue.value = 'week'
  sleepValue.value = ''
  patientData.value = data
  chatTime.value = []
  signSelIndex.value = 0
  yAxisName.value = ''
  chartTitle.value = ''
  chartTip.value = ''
  bsType.value = ''
  xAxisData.value = []
  sericeData.value = []
  if (myChart) {
    myChart.dispose()
    myChart = null
  }
  patientEmpi.value = id

  await getSignsInfoRealData()

  const signLabelData = signLabel.find((vo) => vo.code == labelName)
  let labelIndex = 0
  if (signLabelData) {
    labelIndex = labelName ? signData.value.findIndex((vo) => vo.name == signLabelData.name) : 0
  } else {
    labelIndex = labelName ? signData.value.findIndex((vo) => vo.code == labelName) : 0
  }

  labelIndex = labelIndex < 0 ? 0 : labelIndex
  signHandle(labelIndex, signData.value[labelIndex])

  // columns.value = []
  // signSelCode.value = ['height']
  // chartTitle.value = '身高变化情况'
  // yAxisName.value = '单位：cm'
  // columns.value = [
  //   ...initcolumns.value,
  //   {
  //     title: '身高(cm)',
  //     key: 'height',
  //     dataIndex: 'height'
  //   }
  // ]
  // // 获取具体的体征数据
  // await getSignsInfoData()
  // initChartData()

  window.addEventListener('resize', () => {
    if (myChart) {
      myChart.resize()
    }
  })
}

// 获取当前周日期
const getCurrentWeekDates = (type) => {
  let currentDate = null
  if (type == 'before') {
    currentDate = new Date(new Date(getShowDateStartOld.value).getTime() - 7 * 24 * 3600 * 1000)
  } else if (type == 'after') {
    currentDate = new Date(new Date(getShowDateEndOld.value).getTime() + 1 * 24 * 3600 * 1000)
  } else {
    currentDate = new Date()
  }
  const currentDayOfWeek = currentDate.getDay() // 0 (Sunday) through 6 (Saturday)
  const startDate = new Date(currentDate)
  const endDate = new Date(currentDate)
  // 计算起始日期（周一）
  startDate.setDate(startDate.getDate() - currentDayOfWeek + 1)
  // 计算结束日期（周日）
  endDate.setDate(endDate.getDate() - currentDayOfWeek + 7)
  // 将日期转换为 YYYY-MM-DD 格式
  const start = formatDateTime(startDate, 'date')
  const end = formatDateTime(endDate, 'date')
  return { start, end }
}
// 获取月份
const geMonthDates = (type) => {
  let date = ''
  if (type == 'before') {
    date = new Date(new Date(getShowDateStartOld.value).getTime() - 1 * 24 * 3600 * 1000)
  } else if (type == 'after') {
    date = new Date(new Date(getShowDateEndOld.value).getTime() + 1 * 24 * 3600 * 1000)
  } else {
    date = new Date()
  }
  const start = formatDateTime(new Date(date.getFullYear(), date.getMonth(), 1), 'date')
  const end = formatDateTime(new Date(date.getFullYear(), date.getMonth() + 1, 0), 'date')
  return { start, end }
}
const geYearDates = (type) => {
  let date = ''
  if (type == 'before') {
    date = new Date(new Date(getShowDateStartOld.value).getTime() - 1 * 24 * 3600 * 1000)
  } else if (type == 'after') {
    date = new Date(new Date(getShowDateEndOld.value).getTime() + 1 * 24 * 3600 * 1000)
  } else {
    date = new Date()
  }
  const yearOld = formatDateTime(new Date(date), 'year')
  const start = formatDateTime(new Date(yearOld + '-1-1'), 'date')
  const end = formatDateTime(new Date(yearOld + '-12-31'), 'date')
  return { start, end }
}
const radioChange = async () => {
  let time = null
  if (getDateValue.value == 'week') {
    time = await getCurrentWeekDates('')
  } else if (getDateValue.value == 'month') {
    time = await geMonthDates('')
  } else if (getDateValue.value == 'year') {
    time = await geYearDates('')
  }

  getShowDateStartOld.value = time.start
  getShowDateEndOld.value = time.end
  getShowDateStart.value = formatDateTime(time.start, 'check-Y-D')
  getShowDateEnd.value = formatDateTime(time.end, 'check-Y-D')
  pagination.value.current = 1
  if (
    signSelCode.value[0] == 'water' ||
    signSelCode.value[0] == 'sleep' ||
    signSelCode.value[0] == 'blood_ketone' ||
    signSelCode.value[0] == 'uric_acid' ||
    signSelCode.value[0] == 'blood_fat' ||
    signSelCode.value[0] == 'liver_function' ||
    signSelCode.value[0] == 'blood_sugar'
  ) {
    await getNewSignsInfoData()
  } else {
    await getSignsInfoData()
  }
  if (signSelCode.value[0] != 'sleep') {
    await initChartData()
  } else {
    if (sericeDataSleepList.value && sericeDataSleepList.value.length > 0) {
      await initChartDataTwo(sericeDataSleepList.value, sericeDataLists.value)
    } else {
      sericeDataSleepList.value = []
      sericeDataLists.value = []
    }
  }
}
const targetTime = async (type) => {
  let time = null
  if (getDateValue.value == 'week') {
    time = await getCurrentWeekDates(type)
  } else if (getDateValue.value == 'month') {
    time = await geMonthDates(type)
  } else if (getDateValue.value == 'year') {
    time = await geYearDates(type)
  }
  getShowDateStartOld.value = time.start
  getShowDateEndOld.value = time.end
  getShowDateStart.value = formatDateTime(time.start, 'check-Y-D')
  getShowDateEnd.value = formatDateTime(time.end, 'check-Y-D')
  pagination.value.current = 1

  if (
    signSelCode.value[0] == 'water' ||
    signSelCode.value[0] == 'sleep' ||
    signSelCode.value[0] == 'blood_ketone' ||
    signSelCode.value[0] == 'uric_acid' ||
    signSelCode.value[0] == 'blood_fat' ||
    signSelCode.value[0] == 'liver_function' ||
    signSelCode.value[0] == 'blood_sugar'
  ) {
    await getNewSignsInfoData()
  } else {
    await getSignsInfoData()
  }
  if (signSelCode.value[0] != 'sleep') {
    await initChartData()
  } else {
    if (sericeDataSleepList.value && sericeDataSleepList.value.length > 0) {
      await initChartDataTwo(sericeDataSleepList.value, sericeDataLists.value)
    } else {
      sericeDataSleepList.value = []
      sericeDataLists.value = []
    }
  }
}

// 获取实时的监测数据
const getSignsInfoRealData = async () => {
  getPatientTest({ empi: patientEmpi.value }).then((res) => {
    signData.value.forEach((item) => {
      if (item.code == 'bp') {
        const valueNew = res.data['sbp'] ? res.data['sbp'].itemValue : ''
        const valueNew1 = res.data['dbp'] ? res.data['dbp'].itemValue : ''
        item.value = valueNew ? parseFloat(valueNew).toFixed(item.decimal) : '-'
        item.value1 = valueNew1 ? parseFloat(valueNew1).toFixed(item.decimal) : '-'

        item.status =
          res.data['sbp'] && res.data['sbp'].normalFlag
            ? res.data['sbp'].normalFlag == 'N'
              ? 'normal'
              : 'abnormal'
            : ''
        item.status1 =
          res.data['dbp'] && res.data['dbp'].normalFlag
            ? res.data['dbp'].normalFlag == 'N'
              ? 'normal'
              : 'abnormal'
            : ''
      } else if (item.code == 'bs') {
        // 血糖 fbg pbg
        if (res.data['fbg'] && res.data['fbg'].itemValue) {
          item.value = res.data['fbg'].itemValue
            ? parseFloat(res.data['fbg'].itemValue).toFixed(item.decimal)
            : '-'
          item.status = res.data['fbg'].normalFlag
            ? res.data['fbg'].normalFlag == 'N'
              ? 'normal'
              : 'abnormal'
            : ''
        }
        if (res.data['pbg'] && res.data['pbg'].itemValue) {
          item.value = res.data['pbg'].itemValue
            ? parseFloat(res.data['pbg'].itemValue).toFixed(item.decimal)
            : '-'
          item.status = res.data['pbg'].normalFlag
            ? res.data['pbg'].normalFlag == 'N'
              ? 'normal'
              : 'abnormal'
            : ''
        }
      } else {
        if (res.data[item.code]) {
          item.value = res.data[item.code].itemValue
            ? parseFloat(res.data[item.code].itemValue).toFixed(item.decimal)
            : '-'
          if (item.code == 'height' || item.code == 'weight') {
            item.status = 'N'
          } else {
            item.status = res.data[item.code].normalFlag
              ? res.data[item.code].normalFlag == 'N'
                ? 'normal'
                : 'abnormal'
              : ''
          }
        }
      }
    })
  })
}

// 血糖类型切换
const bsTypeChange = async (value: event) => {
  // chatTime.value = []
  bsType.value = value.target.value
  if (myChart) {
    myChart.clear()
  }
  xAxisData.value = []
  sericeData.value = []
  await getNewSignsInfoData()
  setTimeout(() => {
    initChartData()
  }, 100)
}

const getSignsInfoData = async () => {
  chartTip.value = ''
  loading.value = true
  xAxisData.value = []

  //   if (getDateValue.value == 'year') {
  await getPatientSigns({
    empi: patientEmpi.value,
    begin: getShowDateStartOld.value ? getShowDateStartOld.value + ' 00:00:00' : '',
    end: getShowDateEndOld.value ? getShowDateEndOld.value + ' 23:59:59' : '',
    itemList: signSelCode.value
  })
    .then((res) => {
      loading.value = false
      if (res.data.length) {
        if (signSelCode.value[0] == 'fbg') {
          List.value = res.data.map((item) => {
            return {
              ...item,
              type: item.fbg ? '空腹血糖' : '餐后2小时'
            }
          })
        } else {
          List.value = res.data
        }
      }
    })
    .catch((err) => {
      List.value = []
      loading.value = false
    })
  await infoCharts({
    empi: patientEmpi.value,
    // empi: 'cf9f8460692912298707fd57867f81fe',
    startTime: getShowDateStartOld.value ? getShowDateStartOld.value + ' 00:00:00' : '',
    endTime: getShowDateEndOld.value ? getShowDateEndOld.value + ' 23:59:59' : '',
    paramKey: signSelCode.value[0],
    timeType:
      getDateValue.value && getDateValue.value == 'week'
        ? 'WEEK'
        : getDateValue.value && getDateValue.value == 'month'
          ? 'MONTH'
          : 'YEAR'
  })
    .then((res) => {
      loading.value = false
      switch (signSelCode.value[0]) {
        case 'bmi':
          chartTip.value = `正常范围:18.5-23.9`
          break
        case 'whr':
          chartTip.value = `男性≤0.9，女性≤0.85`
          break
        case 'sbp':
          chartTip.value = `舒张压正常范围:60-89\n收缩压正常范围:90-139`
          break
        case 'heart_rate':
          chartTip.value = `心率正常范围:60-100`
          break
        case 'fbg':
          chartTip.value = `空腹血糖正常范围:3.9-6.1\n餐后2小时血糖正常:<7.8`
          break
        case 'spo2':
          chartTip.value = `血氧正常范围:95-100`
          break
        default:
          break
      }

      if (res.data.length) {
        let dataListTwo = []
        xAxisData.value = []
        const ValueList = []
        if (getDateValue.value == 'year') {
          dataListTwo =
            res.data && res.data.length > 0
              ? res.data.sort((a, b) => {
                  return a.dateName - b.dateName
                })
              : []
          for (let i = 0; i < dataListTwo.length; i++) {
            xAxisData.value.push(
              formatDateTime(getShowDateStartOld.value, 'year') + '-' + dataListTwo[i].dateName
            )
            if (signSelCode.value[0] == 'bmi') {
              ValueList.push(dataListTwo[i].param_value.toFixed(1))
            } else {
              ValueList.push(dataListTwo[i].param_value)
            }
          }
        } else {
          dataListTwo =
            res.data && res.data.length > 0
              ? res.data.sort((a, b) => {
                  return new Date(a.dateName) - new Date(b.dateName)
                })
              : []
          for (let i = 0; i < dataListTwo.length; i++) {
            xAxisData.value.push(formatDateTime(dataListTwo[i].dateName, 'date'))
            if (signSelCode.value[0] == 'bmi') {
              ValueList.push(dataListTwo[i].param_value.toFixed(1))
            } else {
              ValueList.push(dataListTwo[i].param_value)
            }
          }
        }

        if (signSelCode.value[0] == 'sbp') {
          infoCharts({
            empi: patientEmpi.value,
            // empi: 'cf9f8460692912298707fd57867f81fe',
            startTime: getShowDateStartOld.value ? getShowDateStartOld.value + ' 00:00:00' : '',
            endTime: getShowDateEndOld.value ? getShowDateEndOld.value + ' 23:59:59' : '',
            paramKey: 'dbp',
            timeType:
              getDateValue.value && getDateValue.value == 'week'
                ? 'WEEK'
                : getDateValue.value && getDateValue.value == 'month'
                  ? 'MONTH'
                  : 'YEAR'
          }).then((resTwo) => {
            const dataListThree =
              resTwo.data && resTwo.data.length > 0
                ? resTwo.data.sort((a, b) => {
                    return new Date(a.dateName) - new Date(b.dateName)
                  })
                : []
            const ValueListTwo = []
            for (let i = 0; i < dataListTwo.length; i++) {
              ValueListTwo.push(dataListThree[i].param_value)
            }
            switch (signSelCode.value[0]) {
              case 'sbp':
                sericeData.value = [
                  {
                    name: '收缩压',
                    type: 'line',
                    // showSymbol: false,
                    symbol: 'circle',
                    data: ValueList,
                    markArea: {
                      silent: true,
                      itemStyle: {
                        opacity: 0.3
                      },
                      data: [
                        [
                          {
                            // name: '收缩压正常范围90-139',
                            yAxis: 90
                          },
                          {
                            yAxis: 139
                          }
                        ]
                      ]
                    }
                  },
                  {
                    name: '舒张压',
                    type: 'line',
                    // showSymbol: false,
                    symbol: 'circle',
                    data: ValueListTwo,
                    markArea: {
                      silent: true,
                      itemStyle: {
                        opacity: 0.3
                      },
                      data: [
                        [
                          {
                            // name: '舒张压正常范围60-89',
                            yAxis: 60
                          },
                          {
                            yAxis: 89
                          }
                        ]
                      ]
                    }
                  }
                ]
                break
              default:
                break
            }
            setTimeout(() => {
              initChartData()
            }, 20)
          })
        } else {
          switch (signSelCode.value[0]) {
            case 'height':
              sericeData.value = [
                {
                  name: '身高(cm)',
                  type: 'line',
                  // showSymbol: false,
                  symbol: 'circle',
                  data: ValueList
                }
              ]
              break
            case 'weight':
              sericeData.value = [
                {
                  name: '体重(kg)',
                  type: 'line',
                  // showSymbol: false,
                  symbol: 'circle',
                  data: ValueList
                }
              ]
              break
            case 'bmi':
              sericeData.value = [
                {
                  name: 'BMI',
                  type: 'line',
                  // showSymbol: false,
                  symbol: 'circle',
                  data: ValueList,
                  markArea: {
                    silent: true,
                    itemStyle: {
                      opacity: 0.3
                    },
                    data: [
                      [
                        {
                          // name: '正常范围18.5-23.9',
                          yAxis: 23.9
                        },
                        {
                          yAxis: 18.5
                        }
                      ]
                    ]
                  }
                }
              ]
              break
            case 'whr':
              sericeData.value = [
                {
                  name: '腰臀比',
                  type: 'line',
                  // showSymbol: false,
                  symbol: 'circle',
                  data: ValueList,
                  markLine: {
                    symbol: 'none',
                    label: { show: false },
                    silent: true,
                    data: [
                      {
                        yAxis: patientData.value.gender == '女性' ? '0.85' : '0.9',
                        symbol: 'none',
                        lineStyle: {
                          type: 'solid'
                        }
                      }
                    ]
                  }
                }
              ]
              break
            case 'heart_rate':
              sericeData.value = [
                {
                  name: '心率',
                  type: 'line',
                  // showSymbol: false,
                  symbol: 'circle',
                  data: ValueList,
                  markArea: {
                    silent: true,
                    itemStyle: {
                      opacity: 0.3
                    },
                    data: [
                      [
                        {
                          // name: '心率正常范围60-100',
                          yAxis: 60
                        },
                        {
                          yAxis: 100
                        }
                      ]
                    ]
                  }
                }
              ]
              break
            case 'spo2':
              sericeData.value = [
                {
                  name: '血氧',
                  type: 'line',
                  // showSymbol: false,
                  symbol: 'circle',
                  data: ValueList,
                  markArea: {
                    silent: true,
                    itemStyle: {
                      opacity: 0.3
                    },
                    data: [
                      [
                        {
                          // name: '血氧正常范围95-100',
                          yAxis: 95
                        },
                        {
                          yAxis: 100
                        }
                      ]
                    ]
                  }
                }
              ]
              break
            default:
              break
          }
        }
      } else {
        sericeData.value = []
        xAxisData.value = []
      }
    })
    .catch((err) => {
      sericeData.value = []
      xAxisData.value = []
      loading.value = false
    })
}

const getNewSignsInfoData = async () => {
  chartTip.value = ''
  loading.value = true
  xAxisData.value = []
  sericeDataSleepList.value = []
  sericeDataLists.value = []
  switch (signSelCode.value[0]) {
    case 'water':
      chartTip.value = `饮水正常范围:≥2000`
      break
    case 'sleep':
      chartTip.value = `睡眠正常范围:≥7`
      break
    case 'spo2':
      chartTip.value = `血氧正常范围:95-100`
      break
    case 'blood_ketone':
      chartTip.value = `血酮正常范围:0.03-0.3`
      break
    case 'uric_acid':
      if (patientData.value.gender == '女性') {
        chartTip.value = `女性≥89 或 女性≤357`
      } else {
        chartTip.value = `男性≥149 或 男性≤416`
      }
      break
    case 'blood_fat':
      chartTip.value = `总胆固醇正常范围:2.2-5.7  \n甘油三酯正常范围:0.2-1.7  \n高密度脂蛋白胆固醇正常范围:0.9-1.7  \n低密度脂蛋白胆固醇正常范围:≤3.6`
      break
    case 'liver_function':
      chartTip.value = `谷草转氨酶正常范围:15-40  \n谷丙转氨酶正常范围:9-50  \nY-谷氨酰转肽酶正常范围:7-45 `
      break
    case 'blood_sugar':
      chartTip.value = `餐前≥3.9 或 餐前≤6.1  \n餐后≥3.9 或 餐后≤7.8`
      break
    // case 'fbg':
    //   chartTip.value = `空腹血糖正常范围:3.9-6.1\n餐后2小时血糖正常:<7.8`
    //   break
    default:
      break
  }
  if (signSelCode.value && (signSelCode.value[0] == 'water' || signSelCode.value[0] == 'sleep')) {
    await getNewPatientSigns({
      empi: patientEmpi.value,
      // empi: 'cf9f8460692912298707fd57867f81fe',
      begin: getShowDateStartOld.value ? getShowDateStartOld.value + ' 00:00:00' : '',
      end: getShowDateEndOld.value ? getShowDateEndOld.value + ' 23:59:59' : '',
      itemList: signSelCode.value
    })
      .then((res) => {
        loading.value = false
        let dataList = []
        if (res.data.length) {
          let ValueList = []

          if (signSelCode.value[0] == 'water') {
            dataList =
              res.data && res.data.length > 0
                ? res.data.sort((a, b) => {
                    return (
                      new Date(JSON.parse(a.paramValue).weekupTime) -
                      new Date(JSON.parse(b.paramValue).weekupTime)
                    )
                  })
                : []
            const reverseData = res.data.slice().reverse()

            for (let i = 0; i < dataList.length; i++) {
              dataList[i].dataSourceTwo =
                dataList[i].dataSource == '医院体检中心' ? '手工录入' : dataList[i].dataSource
              dataList[i].paramValueTwo = Number(JSON.parse(dataList[i].paramValue).sleepDuration)
            }
            List.value = dataList
            reverseData.forEach((element) => {
              if (element.collectTime) {
                const time = dayjs(element.collectTime).format('YYYY-MM-DD HH:mm')
                xAxisData.value.push(time)
              }
            })
            ValueList = reverseData
              .filter((ele) => ele.collectTime)
              .map((item) => {
                return item.paramValue
              })
            switch (signSelCode.value[0]) {
              case 'water':
                sericeData.value = [
                  {
                    name: '饮水量',
                    type: 'line',
                    // showSymbol: false,
                    symbol: 'circle',
                    data: ValueList,
                    markArea: {
                      silent: true,
                      itemStyle: {
                        opacity: 0.3
                      },
                      data: [
                        [
                          {
                            yAxis: Math.max(...ValueList) + 1000
                          },
                          {
                            yAxis: 2000
                            // yAxis: 1600
                          }
                        ]
                      ]
                    }
                  }
                ]
                break
              default:
                break
            }
          } else if (signSelCode.value[0] == 'sleep') {
            if (getDateValue.value != 'year') {
              dataList =
                res.data && res.data.length > 0
                  ? res.data.sort((a, b) => {
                      return (
                        new Date(JSON.parse(a.paramValue).weekupTime) -
                        new Date(JSON.parse(b.paramValue).weekupTime)
                      )
                    })
                  : []
              const dataLists = []
              const collectTime = []
              for (let i = 0; i < dataList.length; i++) {
                dataList[i].dataSourceTwo =
                  dataList[i].dataSource == '医院体检中心' ? '手工录入' : dataList[i].dataSource
                dataList[i].paramValueTwo = Number(JSON.parse(dataList[i].paramValue).sleepDuration)
              }
              List.value = dataList
              if (dataList && dataList.length > 0) {
                for (let i = 0; i < dataList.length; i++) {
                  const collectTimes = formatDateTime(
                    JSON.parse(dataList[i].paramValue).weekupTime,
                    'date'
                  )
                  collectTime.push(collectTimes)
                  const obj = {}
                  obj.sleepTime = JSON.parse(dataList[i].paramValue).sleepTime
                  obj.weekupTime = JSON.parse(dataList[i].paramValue).weekupTime
                  obj.sleepDuration = JSON.parse(dataList[i].paramValue).sleepDuration
                  if (collectTimes == formatDateTime(obj.weekupTime, 'date')) {
                    obj.weekupTimeHours = formatDateTime(
                      JSON.parse(dataList[i].paramValue).weekupTime,
                      'hours'
                    )
                  } else {
                    obj.weekupTimeHours = formatDateTimeTwo(
                      JSON.parse(dataList[i].paramValue).sleepTime,
                      JSON.parse(dataList[i].paramValue).weekupTime,
                      'hours'
                    )
                  }
                  obj.Hours = formatDateTime(
                    JSON.parse(dataList[i].paramValue).sleepTime,
                    'hoursStr'
                  )
                  obj.weekUpHourTime = formatDateTime(
                    JSON.parse(dataList[i].paramValue).weekupTime,
                    'hoursStr'
                  )
                  obj.endTime = 18 - obj.weekupTimeHours
                  dataLists.push(obj)
                }
                if (collectTime && collectTime.length > 0) {
                  sericeDataSleepList.value = collectTime
                  sericeDataLists.value = dataLists
                }
              } else {
                sericeDataSleepList.value = []
                sericeDataLists.value = []
              }
            } else {
              dataList = res.data && res.data.length > 0 ? res.data : []
              for (let i = 0; i < dataList.length; i++) {
                dataList[i].dataSourceTwo =
                  dataList[i].dataSource == '医院体检中心' ? '手工录入' : dataList[i].dataSource
                dataList[i].paramValueTwo = Number(JSON.parse(dataList[i].paramValue).sleepDuration)
              }
              List.value = dataList
            }
          }
        } else {
          List.value = []
          sericeData.value = []
          xAxisData.value = []
          sericeDataSleepList.value = []
          sericeDataLists.value = []
        }
      })
      .catch((err) => {
        List.value = []
        sericeData.value = []
        xAxisData.value = []
        sericeDataSleepList.value = []
        sericeDataLists.value = []

        loading.value = false
      })
    if (getDateValue.value == 'year') {
      await infoCharts({
        empi: patientEmpi.value,
        // empi: 'cf9f8460692912298707fd57867f81fe',
        startTime: getShowDateStartOld.value ? getShowDateStartOld.value + ' 00:00:00' : '',
        endTime: getShowDateEndOld.value ? getShowDateEndOld.value + ' 23:59:59' : '',
        paramKey: signSelCode.value[0],
        timeType: 'YEAR'
      })
        .then((res) => {
          loading.value = false
          if (res.data.length) {
            if (signSelCode.value[0] == 'water') {
              const dataListTwo =
                res.data && res.data.length > 0
                  ? res.data.sort((a, b) => {
                      return a.dateName - b.dateName
                    })
                  : []
              const ValueList = []
              xAxisData.value = []
              for (let i = 0; i < dataListTwo.length; i++) {
                xAxisData.value.push(
                  formatDateTime(getShowDateStartOld.value, 'year') + '-' + dataListTwo[i].dateName
                )
                ValueList.push(dataListTwo[i].param_value_avg)
              }
              switch (signSelCode.value[0]) {
                case 'water':
                  sericeData.value = [
                    {
                      name: '饮水量',
                      type: 'line',
                      // showSymbol: false,
                      symbol: 'circle',
                      data: ValueList,
                      markArea: {
                        silent: true,
                        itemStyle: {
                          opacity: 0.3
                        },
                        data: [
                          [
                            {
                              yAxis: Math.max(...ValueList) + 1000
                            },
                            {
                              yAxis: 2000
                              // yAxis: 1600
                            }
                          ]
                        ]
                      }
                    }
                  ]
                  break
                default:
                  break
              }
            } else if (signSelCode.value[0] == 'sleep') {
              const dataListWrap = res.data && res.data.length > 0 ? res.data : []
              const dataListWrapTwo = []
              if (dataListWrap && dataListWrap.length > 0) {
                for (let i = 0; i < dataListWrap.length; i++) {
                  if (dataListWrap[i].weekupTime) {
                    dataListWrapTwo.push(dataListWrap[i])
                  }
                }
              }

              const dataListTwo = dataListWrapTwo.sort((a, b) => {
                return a.dateName - b.dateName
              })
              const dataLists = []
              const collectTime = []
              for (let i = 0; i < dataListTwo.length; i++) {
                const collectTimes =
                  formatDateTime(getShowDateStartOld.value, 'year') + '-' + dataListTwo[i].dateName
                collectTime.push(collectTimes)
                const obj = {}
                obj.sleepTime = dataListTwo[i].weekupTime
                  ? formatDateTime(getShowDateStartOld.value, 'year') +
                    '-' +
                    dataListTwo[i].dateName +
                    '-14' +
                    ' ' +
                    dataListTwo[i].sleepTime
                  : ''
                obj.weekupTime = dataListTwo[i].weekupTime
                  ? formatDateTime(getShowDateStartOld.value, 'year') +
                    '-' +
                    dataListTwo[i].dateName +
                    '-15' +
                    ' ' +
                    dataListTwo[i].weekupTime
                  : ''

                obj.sleepDuration = dataListTwo[i].sleepDuration
                // if (collectTimes == formatDateTime(obj.weekupTime, 'date')) {
                //   obj.weekupTimeHours = formatDateTime(
                //     JSON.parse(dataListTwo[i].paramValue).weekupTime,
                //     'hours'
                //   )
                // } else {
                //   obj.weekupTimeHours = formatDateTimeTwo(
                //     JSON.parse(dataListTwo[i].paramValue).sleepTime,
                //     JSON.parse(dataListTwo[i].paramValue).weekupTime,
                //     'hours'
                //   )
                // }
                // obj.weekupTimeHours = formatDateTimeTwo(obj.sleepTime, obj.weekupTime, 'hours')
                obj.weekupTimeHours = formatDateTime(obj.weekupTime, 'hours')
                obj.Hours = formatDateTime(obj.sleepTime, 'hoursStr')
                obj.weekUpHourTime = formatDateTime(obj.weekupTime, 'hoursStr')
                obj.endTime = 18 - obj.weekupTimeHours
                dataLists.push(obj)
              }
              if (collectTime && collectTime.length > 0) {
                sericeDataSleepList.value = collectTime
                sericeDataLists.value = dataLists
              }
            }
          } else {
            // List.value = []
            sericeData.value = []
            xAxisData.value = []
            sericeDataSleepList.value = []
            sericeDataLists.value = []
          }
        })
        .catch((err) => {
          List.value = []
          sericeData.value = []
          xAxisData.value = []
          sericeDataSleepList.value = []
          sericeDataLists.value = []

          loading.value = false
        })
    }
  } else if (
    signSelCode.value &&
    (signSelCode.value[0] == 'blood_ketone' ||
      signSelCode.value[0] == 'uric_acid' ||
      signSelCode.value[0] == 'blood_fat' ||
      signSelCode.value[0] == 'liver_function' ||
      signSelCode.value[0] == 'blood_sugar')
  ) {
    await reportChart({
      empi: patientEmpi.value,
      //   empi: '8b436fbbe8731884cfb95b80a23bab18',
      startTime: getShowDateStartOld.value ? getShowDateStartOld.value + ' 00:00:00' : '',
      endTime: getShowDateEndOld.value ? getShowDateEndOld.value + ' 23:59:59' : '',
      timeType: getDateValue.value,
      indicatorKey: signSelCode.value[0]
    })
      .then((res) => {
        List.value = []
        let ValueListTwo = []
        let ValueListThree = []
        let ValueListFour = []
        // switch (signSelCode.value[0]) {
        //   // case 'bmi':
        //   //   chartTip.value = `正常范围:18.5-23.9`
        //   //   break
        //   // case 'whr':
        //   //   chartTip.value = `男性≤0.9，女性≤0.85`
        //   //   break
        //   //   case 'sbp':
        //   //     chartTip.value = `舒张压正常范围:60-89\n收缩压正常范围:90-139`
        //   //     break
        //   case 'blood_ketone':
        //     chartTip.value = `血酮正常范围:0.03-0.3`
        //     break
        //   case 'uric_acid':
        //     if (patientData.value.gender == '女性') {
        //       chartTip.value = `女性≥89 或 女性≤357`
        //     } else {
        //       chartTip.value = `男性≥149 或 男性≤416`
        //     }
        //     break
        //   case 'blood_fat':
        //     chartTip.value = `总胆固醇正常范围:2.2-5.7  \n甘油三酯正常范围:0.2-1.7  \n高密度脂蛋白胆固醇正常范围:0.9-1.7  \n低密度脂蛋白胆固醇正常范围:≤3.6`
        //     break
        //   case 'liver_function':
        //     chartTip.value = `谷草转氨酶正常范围:15-40  \n谷丙转氨酶正常范围:9-50  \nY-谷氨酰转肽酶正常范围:7-45 `
        //     break
        //   case 'blood_sugar':
        //     chartTip.value = `餐前≥3.9 或 餐前≤6.1  \n餐后≥3.9 或 餐后≤7.8`
        //     break
        //   // case 'fbg':
        //   //   chartTip.value = `空腹血糖正常范围:3.9-6.1\n餐后2小时血糖正常:<7.8`
        //   //   break
        //   case 'spo2':
        //     chartTip.value = `血氧正常范围:95-100`
        // }
        let signSelData = []
        let bloodSugarName = ''
        if (signSelCode.value[0] == 'blood_ketone') {
          signSelData = res.data.blood_ketone_data.sort((a, b) => {
            return new Date(b.checkDate) - new Date(a.checkDate)
          })
        } else if (signSelCode.value[0] == 'uric_acid') {
          signSelData = res.data.uric_acid_data.sort((a, b) => {
            return new Date(b.checkDate) - new Date(a.checkDate)
          })
        } else if (signSelCode.value[0] == 'blood_fat') {
          signSelData = res.data.hdlc.sort((a, b) => {
            return new Date(b.checkDate) - new Date(a.checkDate)
          })
          const reverseDataTwoList = res.data.ldlc.sort((a, b) => {
            return new Date(a.checkDate) - new Date(b.checkDate)
          })
          const reverseDataThreeList = res.data.tg.sort((a, b) => {
            return new Date(a.checkDate) - new Date(b.checkDate)
          })
          const reverseDataFourList = res.data.total_cholesterol.sort((a, b) => {
            return new Date(a.checkDate) - new Date(b.checkDate)
          })
          ValueListTwo = reverseDataTwoList
            .filter((ele) => ele.checkDate)
            .map((item) => {
              return Number(item.indicatorValue)
            })
          ValueListThree = reverseDataThreeList
            .filter((ele) => ele.checkDate)
            .map((item) => {
              return Number(item.indicatorValue)
            })
          ValueListFour = reverseDataFourList
            .filter((ele) => ele.checkDate)
            .map((item) => {
              return Number(item.indicatorValue)
            })
        } else if (signSelCode.value[0] == 'liver_function') {
          signSelData = res.data.got.sort((a, b) => {
            return new Date(b.checkDate) - new Date(a.checkDate)
          })
          const reverseDataTwoList = res.data.gpt.sort((a, b) => {
            return new Date(a.checkDate) - new Date(b.checkDate)
          })
          const reverseDataThreeList = res.data.ygt.sort((a, b) => {
            return new Date(a.checkDate) - new Date(b.checkDate)
          })
          ValueListTwo = reverseDataTwoList
            .filter((ele) => ele.checkDate)
            .map((item) => {
              return Number(item.indicatorValue)
            })
          ValueListThree = reverseDataThreeList
            .filter((ele) => ele.checkDate)
            .map((item) => {
              return Number(item.indicatorValue)
            })
        } else if (signSelCode.value[0] == 'blood_sugar') {
          bloodSugarList.value = res.data
          if (bsType.value == 'fbg') {
            signSelData = res.data.blood_sugar_before.sort((a, b) => {
              return new Date(b.checkDate) - new Date(a.checkDate)
            })
            bloodSugarName = '空腹血糖'
          } else {
            signSelData = res.data.blood_sugar_after.sort((a, b) => {
              return new Date(b.checkDate) - new Date(a.checkDate)
            })
            bloodSugarName = '餐后2小时'
          }
        }
        if (signSelData.length) {
          const reverseData = signSelData.slice().reverse()
          reverseData.forEach((element) => {
            if (element.checkDate) {
              const time = dayjs(element.checkDate).format('YYYY-MM-DD HH:mm')
              xAxisData.value.push(time)
            }
          })
          let ValueList = []
          ValueList = reverseData
            .filter((ele) => ele.checkDate)
            .map((item) => {
              return Number(item.indicatorValue)
            })

          let maxValue = ''
          let minValue = ''
          switch (signSelCode.value[0]) {
            case 'blood_ketone':
              sericeData.value = [
                {
                  name: '血酮',
                  type: 'line',
                  // showSymbol: false,
                  symbol: 'circle',
                  data: ValueList,
                  markArea: {
                    silent: true,
                    itemStyle: {
                      opacity: 0.3
                    },
                    data: [
                      [
                        {
                          yAxis: 0.3
                        },
                        {
                          yAxis: 0.03
                          // yAxis: 1600
                        }
                      ]
                    ]
                  }
                }
              ]
              break
            case 'sleep':
              sericeData.value = [
                {
                  name: '睡眠',
                  type: 'line',
                  // showSymbol: false,
                  symbol: 'circle',
                  data: ValueList,
                  markArea: {
                    silent: true,
                    itemStyle: {
                      opacity: 0.3
                    },
                    data: [
                      [
                        {
                          yAxis: Math.max(...ValueList) + 100
                        },
                        {
                          // yAxis: 2000
                          yAxis: 7
                        }
                      ]
                    ]
                  }
                }
              ]
              break
            case 'uric_acid':
              if (patientData.value.gender == '女性') {
                maxValue = '357'
                minValue = '89'
              } else {
                maxValue = '416'
                minValue = '149'
              }
              sericeData.value = [
                {
                  name: '尿酸',
                  type: 'line',
                  // showSymbol: false,
                  symbol: 'circle',
                  data: ValueList,
                  markArea: {
                    silent: true,
                    itemStyle: {
                      opacity: 0.3
                    },
                    data: [
                      [
                        {
                          yAxis: maxValue
                        },
                        {
                          yAxis: minValue
                          // yAxis: 1600
                        }
                      ]
                    ]
                  }
                }
              ]
              break
            case 'blood_fat':
              sericeData.value = [
                {
                  name: '高密度脂蛋白胆固醇',
                  type: 'line',
                  // showSymbol: false,
                  symbol: 'circle',
                  data: ValueList,
                  markArea: {
                    silent: true,
                    itemStyle: {
                      opacity: 0.3
                    }
                  }
                },
                {
                  name: '低密度脂蛋白胆固醇',
                  type: 'line',
                  // showSymbol: false,
                  symbol: 'circle',
                  data: ValueListTwo,
                  markArea: {
                    silent: true,
                    itemStyle: {
                      opacity: 0.3
                    }
                  }
                },
                {
                  name: '甘油三酯',
                  type: 'line',
                  // showSymbol: false,
                  symbol: 'circle',
                  data: ValueListThree,
                  markArea: {
                    silent: true,
                    itemStyle: {
                      opacity: 0.3
                    }
                  }
                },
                {
                  name: '总胆固醇',
                  type: 'line',
                  // showSymbol: false,
                  symbol: 'circle',
                  data: ValueListFour,
                  markArea: {
                    silent: true,
                    itemStyle: {
                      opacity: 0.3
                    }
                  }
                }
              ]
              break
            case 'liver_function':
              sericeData.value = [
                {
                  name: '谷草转氨酶',
                  type: 'line',
                  // showSymbol: false,
                  symbol: 'circle',
                  data: ValueList,
                  markArea: {
                    silent: true,
                    itemStyle: {
                      opacity: 0.3
                    }
                  }
                },
                {
                  name: '谷丙转氨酶',
                  type: 'line',
                  // showSymbol: false,
                  symbol: 'circle',
                  data: ValueListTwo,
                  markArea: {
                    silent: true,
                    itemStyle: {
                      opacity: 0.3
                    }
                  }
                },
                {
                  name: 'Y-谷氨酰转肽酶',
                  type: 'line',
                  // showSymbol: false,
                  symbol: 'circle',
                  data: ValueListThree,
                  markArea: {
                    silent: true,
                    itemStyle: {
                      opacity: 0.3
                    }
                  }
                }
              ]
              break
            case 'blood_sugar':
              sericeData.value = [
                {
                  name: bloodSugarName,
                  type: 'line',
                  // showSymbol: false,
                  symbol: 'circle',
                  data: ValueList,
                  markArea: {
                    silent: true,
                    itemStyle: {
                      opacity: 0.3
                    },
                    data: [
                      [
                        {
                          // name: '空腹血糖正常范围3.9-6.1',
                          yAxis: bloodSugarName == '空腹血糖' ? '6.1' : '7.8'
                        },
                        {
                          yAxis: 3.9
                        }
                      ]
                    ]
                  }
                }
              ]
              break
            default:
              break
          }
        } else {
          sericeData.value = []
          xAxisData.value = []
        }
      })
      .catch((err) => {
        sericeData.value = []
        xAxisData.value = []
      })
    await queryUserHisReportDetail({
      empi: patientEmpi.value,
      //   empi: '8b436fbbe8731884cfb95b80a23bab18',
      startTime: getShowDateStartOld.value ? getShowDateStartOld.value + ' 00:00:00' : '',
      endTime: getShowDateEndOld.value ? getShowDateEndOld.value + ' 23:59:59' : '',
      timeType: getDateValue.value, //时间类型 week month year "  后期再改 先传空
      indicatorKey: signSelCode.value
    })
      .then((res) => {
        loading.value = false
        let list = res.data
        let listData = []
        const listNewData = []
        if (list && list.length > 0) {
          if (
            signSelCode.value[0] == 'blood_fat' ||
            signSelCode.value[0] == 'liver_function' ||
            signSelCode.value[0] == 'uric_acid' ||
            signSelCode.value[0] == 'blood_ketone'
          ) {
            for (let i = 0; i < list.length; i++) {
              for (let j = 0; j < list[i].details.length; j++) {
                const objs = {}
                if (signSelCode.value[0] == 'blood_fat') {
                  objs.noNumber = i + 1
                  objs.nameTitle = '血脂,' + list[i].report.checkTime
                  objs.names = '血脂'
                  objs.quota =
                    list[i].details[j].indicatorKey == 'hdlc'
                      ? '高密度脂蛋白胆固醇'
                      : list[i].details[j].indicatorKey == 'ldlc'
                        ? '低密度脂蛋白胆固醇'
                        : list[i].details[j].indicatorKey == 'tg'
                          ? '甘油三酯'
                          : list[i].details[j].indicatorKey == 'total_cholesterol'
                            ? '总胆固醇'
                            : ''
                } else if (signSelCode.value[0] == 'liver_function') {
                  objs.noNumber = i + 1
                  objs.nameTitle = '肝功能,' + list[i].report.checkTime
                  objs.names = '肝功能'
                  objs.quota =
                    list[i].details[j].indicatorKey == 'got'
                      ? '谷草转氨酶'
                      : list[i].details[j].indicatorKey == 'gpt'
                        ? '谷丙转氨酶'
                        : list[i].details[j].indicatorKey == 'ygt'
                          ? 'Y-谷氨酰转肽酶'
                          : ''
                } else if (signSelCode.value[0] == 'uric_acid') {
                  objs.nameTitle = '尿酸,' + list[i].report.checkTime
                  objs.names = '尿酸'
                } else if (signSelCode.value[0] == 'blood_ketone') {
                  objs.nameTitle = '血酮,' + list[i].report.checkTime
                  objs.names = '血酮'
                }
                objs.checkTime = list[i].report.checkTime
                objs.collectTimes = list[i].report.checkTime
                objs.color = list[i].report.color
                objs.originReportId = list[i].report.originReportId
                objs.reportId = list[i].report.reportId
                objs.reportSource = list[i].report.reportSource

                objs.dataSource =
                  list[i].report.reportSource == '医院体检中心'
                    ? '手工录入,' + list[i].report.checkTime
                    : list[i].report.reportSource + ',' + list[i].report.checkTime
                objs.dataSourceTwo =
                  list[i].report.reportSource == '医院体检中心'
                    ? '手工录入'
                    : list[i].report.reportSource
                objs.reportStatus = list[i].report.reportStatus
                objs.reportStatusDesc = list[i].report.reportStatusDesc
                objs.timeFat = list[i].report.checkTime
                objs.empi = list[i].details[j].empi
                objs.indicatorKey = list[i].details[j].indicatorKey
                objs.indicatorStatus = list[i].details[j].indicatorStatus
                objs.normalFlagName = list[i].details[j].indicatorStatus == 'N' ? '正常' : '异常'
                objs.indicatorValue = list[i].details[j].indicatorValue
                objs.paramValue = Number(list[i].details[j].indicatorValue)
                objs.parentKey = list[i].details[j].parentKey
                objs.reference = list[i].details[j].reference
                objs.reportId = list[i].details[j].reportId
                listData.push(objs)
              }
            }
          } else if (signSelCode.value[0] == 'blood_sugar') {
            for (let i = 0; i < list.length; i++) {
              for (let j = 0; j < list[i].details.length; j++) {
                const objs = {}
                objs.nameTitle = '血糖' + list[i].report.checkTime
                objs.names = '血糖'
                objs.checkTime = list[i].report.checkTime
                objs.collectTimes = list[i].report.checkTime
                objs.color = list[i].report.color
                objs.originReportId = list[i].report.originReportId
                objs.reportId = list[i].report.reportId
                objs.reportSource = list[i].report.reportSource
                objs.dataSource =
                  list[i].report.reportSource ==
                  list[i].report.reportSource + ',' + list[i].report.checkTime
                objs.dataSourceTwo = list[i].report.reportSource
                objs.reportStatus = list[i].report.reportStatus
                objs.reportStatusDesc = list[i].report.reportStatusDesc
                objs.normalFlagName = list[i].details[j].indicatorStatus == 'N' ? '正常' : '异常'
                objs.timeFat = list[i].report.checkTime
                // objs.timeFat = formatDateTime(list[i].report.checkTime, 'date')
                objs.empi = list[i].details[j].empi
                objs.indicatorKey = list[i].details[j].indicatorKey
                objs.indicatorStatus = list[i].details[j].indicatorStatus
                objs.indicatorValue = list[i].details[j].indicatorValue
                objs.paramValue = Number(list[i].details[j].indicatorValue)
                objs.parentKey = list[i].details[j].parentKey
                objs.reference = list[i].details[j].reference
                objs.reportId = list[i].details[j].reportId
                objs.tag = list[i].details[j].tag
                objs.indicatorName = list[i].details[j].indicatorName
                listNewData.push(objs)
              }
            }
            listData = listNewData
            // for (let i = 0; i < listNewData.length; i++) {
            //   if (bsType.value == 'fbg') {
            //     if (listNewData[i].tag == '餐前') {
            //       listData.push(listNewData[i])
            //     }
            //   } else {
            //     if (listNewData[i].tag == '餐后') {
            //       listData.push(listNewData[i])
            //     }
            //   }
            // }
          }
        } else {
          list = []
          listData = []
        }
        List.value = listData
      })
      .catch((err) => {
        List.value = []
      })
  }
}
const formatDateTime = (timeStamp, returnType) => {
  const date = new Date(timeStamp)
  //   date.setTime(timeStamp * 1000)
  const y = date.getFullYear()
  let m = date.getMonth() + 1
  m = m < 10 ? '0' + m : m
  let d = date.getDate()
  d = d < 10 ? '0' + d : d
  let h = date.getHours()
  h = h < 10 ? '0' + h : h
  let minute = date.getMinutes()
  let second = date.getSeconds()
  minute = minute < 10 ? '0' + minute : minute
  second = second < 10 ? '0' + second : second
  let dateTime = ''
  if (returnType == 'hours') {
    dateTime = Number(date.getHours())
  } else if (returnType == 'date') {
    dateTime = y + '-' + m + '-' + d
  } else if (returnType == 'hoursStr') {
    dateTime = h + ':' + minute
  } else if (returnType == 'check-Y-D') {
    dateTime = m + '/' + d
  } else if (returnType == 'year') {
    dateTime = y
  } else if (returnType == 'month') {
    dateTime = y + '-' + m
  } else if (returnType == 'date-h-m') {
    dateTime = y + '-' + m + '-' + d + ' ' + h + ':' + minute
  }
  return dateTime
}
const formatDateTimeTwo = (timeStamp, timeStampTwo, returnType) => {
  const date = new Date(new Date(timeStampTwo).getTime() - new Date(timeStamp).getTime())
  const y = date.getFullYear()
  let m = date.getMonth() + 1
  m = m < 10 ? '0' + m : m
  let d = date.getDate()
  d = d < 10 ? '0' + d : d
  let h = date.getHours()
  h = h < 10 ? '0' + h : h
  let minute = date.getMinutes()
  let second = date.getSeconds()
  minute = minute < 10 ? '0' + minute : minute
  second = second < 10 ? '0' + second : second
  let dateTime = ''
  if (returnType == 'hours') {
    dateTime = Number(date.getHours()) - 12
  }
  //   else if (returnType == 'date') {
  //     dateTime = y + '-' + m + '-' + d
  //   }
  return dateTime
}

const tableRowSpan = (record, index, column, data) => {
  // 表格列合并
  if (
    index !== 0 &&
    record[column.dataIndex] &&
    record[column.dataIndex] === data[index - 1][column.dataIndex] &&
    data[index - 1].timeFat === data[index].timeFat
  ) {
    return {
      rowSpan: 0 // 表示不渲染
    }
  }
  // 判断下一行是否相等
  let rowSpan = 1
  for (let i = index + 1; i < data.length; i++) {
    if (record[column.dataIndex] !== data[i][column.dataIndex]) {
      break
    }
    rowSpan++
  }
  return { rowSpan: rowSpan }
}
const signHandle = async (index, data) => {
  pagination.value.current = 1
  getDateValue.value = 'week'
  getShowDateStartOld.value = getCurrentWeekDates().start
  getShowDateEndOld.value = getCurrentWeekDates().end
  getShowDateStart.value = formatDateTime(getCurrentWeekDates().start, 'check-Y-D')
  getShowDateEnd.value = formatDateTime(getCurrentWeekDates().end, 'check-Y-D')
  chatTime.value = []
  signSelIndex.value = index
  sleepValue.value = ''
  if (myChart) {
    myChart.dispose()
    myChart = null
  }
  bsType.value = ''
  switch (data.code) {
    case 'height':
      yAxisName.value = '单位：cm'
      signSelCode.value = ['height']
      chartTitle.value = '身高变化情况'
      sleepValue.value = 'height'
      columns.value = [
        ...initcolumns.value,
        {
          title: '身高(cm)',
          key: 'height',
          dataIndex: 'height'
        }
      ]
      break
    case 'weight':
      yAxisName.value = '单位：kg'
      signSelCode.value = ['weight']
      chartTitle.value = '体重变化情况'
      sleepValue.value = 'weight'
      columns.value = [
        ...initcolumns.value,
        {
          title: '体重(kg)',
          key: 'weight',
          dataIndex: 'weight'
        }
      ]
      break
    case 'bmi':
      yAxisName.value = ''
      signSelCode.value = ['bmi']
      chartTitle.value = 'BMI变化情况'
      sleepValue.value = 'bmi'
      columns.value = [
        ...initcolumns.value,
        {
          title: 'BMI',
          key: 'bmi',
          dataIndex: 'bmi'
        },
        {
          title: '结果标识',
          key: 'normalFlagName',
          dataIndex: 'normalFlagName'
        }
      ]
      break
    case 'whr':
      yAxisName.value = ''
      signSelCode.value = ['whr']
      chartTitle.value = '腰臀比变化情况'
      sleepValue.value = 'whr'
      columns.value = [
        ...initcolumns.value,
        {
          title: '腰臀比',
          key: 'whr',
          dataIndex: 'whr'
        },
        {
          title: '结果标识',
          key: 'normalFlagName',
          dataIndex: 'normalFlagName'
        }
      ]
      break

    case 'bp':
      yAxisName.value = '单位：mmHg'
      signSelCode.value = ['sbp', 'dbp']
      chartTitle.value = '血压变化情况'
      sleepValue.value = 'bp'
      columns.value = [
        ...initcolumns.value,
        {
          title: '收缩压(mmHg)',
          key: 'sbp',
          dataIndex: 'sbp'
        },
        {
          title: '舒张压(mmHg)',
          key: 'dbp',
          dataIndex: 'dbp'
        },
        {
          title: '脉搏(次/分)',
          key: 'pulseRate',
          dataIndex: 'pulseRate'
        },
        {
          title: '结果标识',
          key: 'normalFlagName',
          dataIndex: 'normalFlagName'
        }
      ]
      break
    case 'heartRate':
      yAxisName.value = '单位：次/分'
      signSelCode.value = ['heart_rate']
      chartTitle.value = '心率变化情况'
      sleepValue.value = 'heart_rate'
      columns.value = [
        ...initcolumns.value,
        {
          title: '心率(次/分)',
          key: 'heartRate',
          dataIndex: 'heartRate'
        },
        {
          title: '结果标识',
          key: 'normalFlagName',
          dataIndex: 'normalFlagName'
        }
      ]
      break
    case 'blood_sugar':
      bsType.value = 'fbg'
      yAxisName.value = '单位：mmol/L'
      signSelCode.value = ['blood_sugar']
      chartTitle.value = '血糖变化情况'
      sleepValue.value = 'blood_sugar'
      columns.value = [
        {
          title: '编号',
          dataIndex: 'no',
          key: 'no'
        },
        {
          title: '数据来源',
          dataIndex: 'dataSource',
          key: 'dataSource'
        },
        {
          title: '测量时间',
          key: 'timeFat',
          dataIndex: 'timeFat'
        },
        {
          title: '类型',
          key: 'indicatorName',
          dataIndex: 'indicatorName'
        },
        {
          title: '血糖(mmol/L)',
          key: 'paramValue',
          dataIndex: 'paramValue'
        },
        {
          title: '结果标识',
          key: 'normalFlagName',
          dataIndex: 'normalFlagName'
        }
      ]
      break
    case 'spo2':
      yAxisName.value = '单位：%'
      signSelCode.value = ['spo2']
      chartTitle.value = '血氧变化情况'
      sleepValue.value = 'spo2'
      columns.value = [
        ...initcolumns.value,
        {
          title: '血氧(%)',
          key: 'spo2',
          dataIndex: 'spo2'
        },
        {
          title: '结果标识',
          key: 'normalFlagName',
          dataIndex: 'normalFlagName'
        }
      ]
      break
    case 'blood_ketone':
      yAxisName.value = '单位：mmol/L'
      signSelCode.value = ['blood_ketone']
      chartTitle.value = '血酮变化情况'
      sleepValue.value = 'blood_ketone'
      columns.value = [
        {
          title: '编号',
          dataIndex: 'no',
          key: 'no'
        },
        {
          title: '数据来源',
          dataIndex: 'dataSource',
          key: 'dataSource'
        },
        {
          title: '测量时间',
          key: 'timeFat',
          dataIndex: 'timeFat'
        },
        {
          title: '血酮(mmol/L)',
          key: 'paramValue',
          dataIndex: 'paramValue'
        },
        {
          title: '结果标识',
          key: 'normalFlagName',
          dataIndex: 'normalFlagName'
        }
      ]
      break
    case 'uric_acid':
      yAxisName.value = '单位：umol/L'
      signSelCode.value = ['uric_acid']
      chartTitle.value = '尿酸变化情况'
      sleepValue.value = 'uric_acid'
      columns.value = [
        {
          title: '编号',
          dataIndex: 'no',
          key: 'no'
        },
        {
          title: '数据来源',
          dataIndex: 'dataSource',
          key: 'dataSource'
        },
        {
          title: '测量时间',
          key: 'timeFat',
          dataIndex: 'timeFat'
        },
        {
          title: '尿酸(umol/L)',
          key: 'paramValue',
          dataIndex: 'paramValue'
        },
        {
          title: '结果标识',
          key: 'normalFlagName',
          dataIndex: 'normalFlagName'
        }
      ]
      break
    case 'blood_fat':
      yAxisName.value = '单位：mmol/L'
      signSelCode.value = ['blood_fat']
      chartTitle.value = '血脂变化情况'
      sleepValue.value = 'blood_fat'
      columns.value = [
        // ...initcolumns.value,
        {
          title: '编号',
          dataIndex: 'noNumber',
          key: 'noNumber',
          customCell: (record, index, column) => {
            return tableRowSpan(record, index, column, List.value)
          }
        },
        {
          title: '数据名称',
          key: 'nameTitle',
          dataIndex: 'nameTitle',
          customCell: (record, index, column) => {
            return tableRowSpan(record, index, column, List.value)
          }
        },
        {
          title: '数据来源',
          dataIndex: 'dataSource',
          key: 'dataSource',
          customCell: (record, index, column) => {
            return tableRowSpan(record, index, column, List.value)
          }
        },
        {
          title: '指标',
          key: 'quota',
          dataIndex: 'quota'
        },
        {
          title: '测量时间',
          key: 'timeFat',
          dataIndex: 'timeFat',
          customCell: (record, index, column) => {
            return tableRowSpan(record, index, column, List.value)
          }
        },
        {
          title: '血脂(mmol/L)',
          key: 'paramValue',
          dataIndex: 'paramValue'
        },
        {
          title: '结果标识',
          key: 'normalFlagName',
          dataIndex: 'normalFlagName'
        }
      ]
      break
    case 'liver_function':
      yAxisName.value = '单位：U/L'
      signSelCode.value = ['liver_function']
      chartTitle.value = '肝功能变化情况'
      sleepValue.value = 'liver_function'
      columns.value = [
        // ...initcolumns.value,
        {
          title: '编号',
          dataIndex: 'noNumber',
          key: 'noNumber',
          customCell: (record, index, column) => {
            return tableRowSpan(record, index, column, List.value)
          }
        },
        {
          title: '数据名称',
          key: 'nameTitle',
          dataIndex: 'nameTitle',
          customCell: (record, index, column) => {
            return tableRowSpan(record, index, column, List.value)
          }
        },
        {
          title: '数据来源',
          dataIndex: 'dataSource',
          key: 'dataSource',
          customCell: (record, index, column) => {
            return tableRowSpan(record, index, column, List.value)
          }
        },
        {
          title: '指标',
          key: 'quota',
          dataIndex: 'quota'
        },
        {
          title: '测量时间',
          key: 'timeFat',
          dataIndex: 'timeFat',
          customCell: (record, index, column) => {
            return tableRowSpan(record, index, column, List.value)
          }
        },
        {
          title: '肝功能(U/L)',
          key: 'paramValue',
          dataIndex: 'paramValue'
        },
        {
          title: '结果标识',
          key: 'normalFlagName',
          dataIndex: 'normalFlagName'
        }
      ]
      break
    case 'water':
      yAxisName.value = '单位：ml'
      signSelCode.value = ['water']
      chartTitle.value = '饮水量变化情况'
      sleepValue.value = 'water'
      columns.value = [
        ...initcolumns.value,
        {
          title: '饮水量(ml)',
          key: 'paramValue',
          dataIndex: 'paramValue'
        },
        {
          title: '结果标识',
          key: 'normalFlagName',
          dataIndex: 'normalFlagName'
        }
      ]
      break
    case 'sleep':
      yAxisName.value = '单位：小时'
      signSelCode.value = ['sleep']
      chartTitle.value = '睡眠变化情况'
      sleepValue.value = 'sleep'
      columns.value = [
        ...initcolumns.value,
        {
          title: '睡眠(小时)',
          key: 'paramValue',
          dataIndex: 'paramValue'
        },
        {
          title: '结果标识',
          key: 'normalFlagName',
          dataIndex: 'normalFlagName'
        }
      ]
      break
    default:
      break
  }

  await getSignsInfoRealData()
  if (
    data.code == 'water' ||
    data.code == 'sleep' ||
    data.code == 'blood_ketone' ||
    data.code == 'uric_acid' ||
    data.code == 'blood_fat' ||
    data.code == 'liver_function' ||
    data.code == 'blood_sugar'
  ) {
    await getNewSignsInfoData()
  } else {
    await getSignsInfoData()
  }
  if (data.code != 'sleep') {
    initChartData()
  } else {
    if (sericeDataSleepList.value && sericeDataSleepList.value.length > 0) {
      initChartDataTwo(sericeDataSleepList.value, sericeDataLists.value)
    } else {
      sericeDataSleepList.value = []
      sericeDataLists.value = []
    }
  }
}

const chatTimeChange = async (date: string, dateString: string) => {
  pagination.value.current = 1
  if (dateString[0]) {
    //
  } else {
    chatTime.value = []
  }
  if (signSelCode.value[0] == 'water' || signSelCode.value[0] == 'sleep') {
    await getNewSignsInfoData()
  } else {
    await getSignsInfoData()
  }

  initChartData()
}

// 加载图表
const initChartData = () => {
  if (getDateValue.value == 'year') {
    for (let i = 0; i < xAxisData.value.length; i++) {
      xAxisData.value[i] = formatDateTime(xAxisData.value[i], 'month')
    }
  } else {
    if (
      signSelCode.value[0] == 'blood_sugar' ||
      signSelCode.value[0] == 'blood_ketone' ||
      signSelCode.value[0] == 'uric_acid' ||
      signSelCode.value[0] == 'blood_fat' ||
      signSelCode.value[0] == 'liver_function'
    ) {
      for (let i = 0; i < xAxisData.value.length; i++) {
        xAxisData.value[i] = formatDateTime(xAxisData.value[i], 'date')
      }
    }
  }
  if (sericeData.value.length && sericeData.value[0].data.length) {
    const chartMain: any = document.getElementById('chart-main')
    myChart = echarts.getInstanceByDom(chartMain)
    if (!myChart) {
      myChart = echarts.init(chartMain)
    }
    // 修改echarts 图表 option
    const option = {
      tooltip: {
        trigger: 'axis'
      },
      grid: {
        left: '3%',
        right: '4%',
        bottom: 55,
        containLabel: true
      },
      xAxis: {
        type: 'category',
        data: xAxisData.value.map((item) => {
          return item.replace(' ', '\n')
        }),
        axisLine: {
          onZero: false
        },
        axisTick: {
          alignWithLabel: true
        }
      },
      dataZoom: [
        {
          show: true,
          height: 35,
          xAxisIndex: [0],
          bottom: 15,
          startValue: xAxisData.value.length - 9,
          endValue: xAxisData.value.length,
          handleIcon:
            'path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z',
          handleSize: '110%',
          handleStyle: {
            color: '#d3dee5'
          },
          textStyle: {
            color: '#fff'
          },
          borderColor: '#90979c'
        },
        {
          type: 'inside',
          show: true,
          height: 15
        }
      ],
      yAxis: {
        type: 'value',
        name: yAxisName.value,
        nameGap: 10
        // scale: true
      },
      series: sericeData.value
    }
    myChart.setOption(option)
  }
}
const initChartDataTwo = (scollectT, dataL) => {
  let flag = false
  if (dataL && dataL.length > 0) {
    for (let i = 0; i < dataL.length; i++) {
      if (dataL[i].weekupTime != '') {
        flag = true
      }
    }
  }
  if (flag == false) {
    sericeDataSleepList.value = []
  }
  const timeData = dataL.map((item) => {
    return item.endTime
  })
  const timeDuration = dataL.map((item) => {
    return Number(item.sleepDuration)
  })
  const chartMain = document.getElementById('chart-main')
  myChart = echarts.getInstanceByDom(chartMain)
  if (!myChart) {
    myChart = echarts.init(chartMain)
  }
  if (getDateValue.value == 'year') {
    for (let i = 0; i < scollectT.length; i++) {
      scollectT[i] = formatDateTime(scollectT[i], 'month')
    }
  }
  // 修改echarts 图表 option
  const option = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow'
      },
      formatter: function (params) {
        const dateItem = scollectT[params[0].dataIndex]
        const sleepTime = dataL[params[0].dataIndex].Hours
        const weekupTime = dataL[params[0].dataIndex].weekUpHourTime
        const sleepDuration = dataL[params[0].dataIndex].sleepDuration
        return (
          dateItem +
          '<br/>' +
          '入睡时间：' +
          sleepTime +
          '<br/>' +
          '醒来时间：' +
          weekupTime +
          '<br/>' +
          '睡眠时长：' +
          Number(sleepDuration) +
          '小时'
        )
      }
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: 55,
      containLabel: true
    },
    xAxis: {
      type: 'category',
      data: scollectT
    },
    dataZoom: [
      {
        show: true,
        height: 35,
        xAxisIndex: [0],
        bottom: 15,
        startValue: timeData.length - 9,
        endValue: timeData.length,
        handleIcon:
          'path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z',
        handleSize: '110%',
        handleStyle: {
          color: '#d3dee5'
        },
        textStyle: {
          color: '#fff'
        },
        borderColor: '#90979c'
      },
      {
        type: 'inside',
        show: true,
        height: 15
      }
    ],
    yAxis: {
      type: 'value',
      min: 0,
      max: 24,
      interval: 4,
      axisLabel: {
        show: true,
        formatter: function (value) {
          if (value - 18 < 0) {
            if (Math.abs(value - 18) < 10) {
              return '0' + Math.abs(value - 18) + ':00'
            } else {
              return Math.abs(value - 18) + ':00'
            }
          } else {
            if (Math.abs(42 - value) < 10) {
              return '0' + Math.abs(42 - value) + ':00'
            } else {
              return Math.abs(42 - value) + ':00'
            }
          }
        }
      }
    },
    series: [
      {
        name: 'Placeholder',
        type: 'bar',
        stack: 'Total',
        silent: true,
        itemStyle: {
          borderColor: 'transparent',
          color: 'transparent'
        },
        barWidth: '12',
        emphasis: {
          itemStyle: {
            borderColor: 'transparent',
            color: 'transparent'
          }
        },
        data: timeData
      },
      {
        name: 'Income',
        type: 'bar',
        stack: 'Total',
        barWidth: '12',
        label: {
          show: false,
          position: 'top'
        },
        data: timeDuration
      }
    ]
  }
  myChart.setOption(option)
}
defineExpose({
  init
})
</script>
<style lang="less" scoped>
.title-box {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 32px;
  margin: 0 0 10px;
  font-weight: 600;
  line-height: 32px;
  color: #1d2129;

  .title-item-left {
    font-size: 18px;
    font-weight: 600;
  }

  .text-icon {
    display: inline-block;
    width: 3px;
    height: 16px;
    margin-right: 8px;
    line-height: 32px;
    background: #165dff;
  }
}

.health-info .ant-form-item {
  margin-bottom: 10px;
}

.title-item {
  display: flex;
  justify-content: space-between;
  width: 100%;
  height: 32px;
  padding-left: 16px;
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 600;
  line-height: 32px;
  color: #1d2129;
  background: #f7f8fa;

  span {
    font-size: 16px;
    font-weight: 600;
  }
}

.health-box {
  height: calc(100vh - 225px);
  padding-right: 12px;
  overflow: hidden auto;

  .healthMonitoring {
    .healthMonitoringLeft {
      display: inline-block;
      width: 100px;
      height: 100%;
      margin-right: 16px;
      overflow: auto;
      vertical-align: top;

      .left-health {
        width: 100%;

        .sign-item {
          position: relative;
          display: block;
          flex-shrink: 0;
          padding: 12px 0;
          color: #1d2129;
          text-align: center;
          cursor: pointer;
          background: #f7f8fa;
          border-bottom: 1px solid #eff0f3;

          &:nth-last-child(1) {
            border-bottom: 0;
          }

          .sign-item-name {
            font-weight: 600;
          }

          .sign-item-value {
            font-size: 20px;
            font-weight: 600;
          }

          .sign-item-value.normal {
            color: #1d2129;
          }

          .sign-item-value.abnormal {
            color: #f00;
          }

          .sign-item-unit {
            margin-left: 8px;
            font-size: 12px;
            color: #4e5969;
          }

          .sign-item-time {
            display: flex;
            justify-content: space-between;
          }
        }

        .sign-item-active {
          background-color: #fff;
          border-color: #fff;

          .sign-item-name {
            color: #3a66f6;
          }
        }

        .sign-item-active::after {
          position: absolute;
          top: 0;
          right: 0;
          width: 2px;
          height: 100%;
          content: '';
          background: #2d5cf6;
        }
      }
    }

    .healthMonitoringRight {
      display: inline-block;
      width: calc(100% - 116px);
      vertical-align: top;
    }
  }
}

.chart-box {
  flex-direction: column;
  height: 100%;

  .dateLeft {
    float: left;
    margin-left: 6px;
    line-height: 32px;

    .anticon {
      display: inline-block;
      padding: 0 10px;
      vertical-align: middle;

      &:hover {
        cursor: pointer;
        opacity: 0.8;
      }

      &:nth-child(1) {
        transform: rotate(180deg);
      }
    }

    .name {
      display: inline-block;
      margin: 0;
      color: #666;
      vertical-align: middle;
    }
  }

  #chart-main {
    width: 100%;
    height: 320px;
  }

  #chart-tab {
    width: 100%;
  }
}
</style>
<style>
.ant-tooltip {
  max-width: 300px !important;
}
</style>
